package com.xixibaby.redis;

import com.xixibaby.core.dict.SuperDictTool;
import com.xixibaby.redis.aspect.RedisCacheAspect;
import com.xixibaby.redis.service.RedisDictTool;
import org.redisson.Redisson;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

@Configuration
@ConditionalOnClass(Redisson.class)
public class RedisUtilAutoConfituration {

    @Bean
    public Redis redisUtil(){
        return new Redis();
    }

    /**
     * 如果加载了数据库 就加载字典工具
     * @return
     */
    @Bean
    @ConditionalOnBean(DataSource.class)
    public SuperDictTool redisDictTool(){
        return new RedisDictTool();
    }

    @Bean
    @ConditionalOnBean(SuperDictTool.class)
    public Dict dict(){
        return new Dict();
    }

    @Bean
    public RedisCacheAspect redisCacheAspect(){
        return new RedisCacheAspect();
    }

    @Bean
    public Login login(){
        return new Login();
    }

}
